package com.baibei.module;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 金额格式工具类
 * Created by shenminjie on 2017/9/29.
 * mail:shenminjie@100bei.com
 */

public class AmountUtil {

    /**
     * 例如: 入参0.0101----出参1.01%
     *
     * @param precent precent
     * @return return
     */
    public static String formatPrecent(double precent) {
        return new BigDecimal(precent * 100).setScale(2, RoundingMode.DOWN) + "%";
    }

    /**
     * 精度相减
     * 避免19.9-9.9=9.9999999999999
     *
     * @param priceX priceX
     * @param priceY priceY
     * @return return
     */
    public static double minus(double priceX, double priceY) {
        BigDecimal x1 = new BigDecimal(priceX + "");
        BigDecimal x2 = new BigDecimal(priceY + "");
        return x1.subtract(x2).doubleValue();
    }


}
